<template>
<div>
  <el-form ref="form" :model="form" label-width="80px" :inline="true">
    <el-button type="primary" @click="findAll()" class="you">查询</el-button>
    <el-button @click="resetForm('ruleForm')" class="you">重置</el-button>
    <br><br>

    <el-form-item label="" style="margin-left: 90px">
      <el-input v-model="form.badword" style="width: 300px" placeholder="请输入敏感词查询" clearable></el-input>
    </el-form-item>
    <el-button type="primary" @click="toAdd()"  class="you">新增</el-button>
  </el-form>
  <el-table
      :data="tableData"
      style="width: 100%">
    <el-table-column
        prop="id"
        label="序号">
    </el-table-column>
    <el-table-column
        prop="badword"
        label="订单编号">
    </el-table-column>

    <el-table-column
        label="操作">
      <template slot-scope="scope">
        <el-row>
          <el-button type="text" size="small" @click="toUpdate(scope.row.id)" round>修改</el-button>
        </el-row>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[3, 10, 20, 30]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
  </el-pagination>
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="25%"
      >
    <el-form :model="ruleForm"  ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="敏感词" prop="badword">
        <el-input v-model="ruleForm.badword" placeholder="请输入敏感词"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">添加</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</div>

</template>
<script>
import axios from "axios";

export default {
  name: "Lexicon",
  data(){
    return{
      tableData: [],
      pageNum: 1,
      pageSize: 3,
      total: 0,
      form: {},
      ruleForm: {},
      dialogVisible: false,
    }
  },
  methods:{
    handleCurrentChange(val) {
      this.pageNum = val
      this.findAll();
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.findAll();
    },
    findAll() {
      axios.post(`http://localhost:9999/api-function/demand/findAll?pageNum=${this.pageNum}&pageSize=${this.pageSize}`, this.form).then(res => {
        this.tableData = res.data.data.list
        this.total = res.data.data.total
      })
    },
    resetForm() {
      this.form = {}
      this.findPage();
    },
    toAdd(){
      this.ruleForm = {}
      this.dialogVisible = true;
    },
    submitForm() {
      axios.post(`http://localhost:9999/api-function/demand/insertDemand`,this.ruleForm).then(res => {
        if (res.data.code == 200) {
          this.$message.success("添加成功")
        } else {
          this.$message.error("添加失败")
        }
        this.dialogVisible = false;
        this.findAll();
      })
    },
    toUpdate(id){
      axios.post(`http://localhost:9999/api-function/demand/toUpdate?id=${id}`).then(res => {
        this.ruleForm = res.data.data;
        this.dialogVisible = true;
      })
    }
  },
  created(){
      this.findAll();
  },

}
</script>



<style scoped>
.you{
  float: right;
  margin-left: 20px;
}
</style>
